using UnityEngine;
using System.Collections;
using System;

namespace Flaschengeist.Processes 
{
	public class ScreenFadeIn : MonoBehaviour
	{
		private Texture2D fadeTexture;
		private int drawDepth = -1000;
		private float alpha; 
		private bool isFading;
				
		public void Start()
		{
			fadeTexture = (Texture2D)Resources.Load("textures/gui_fade");
		}
		
		public void Process()
		{
			alpha = 1.0f;
			isFading = true;
		}
		
		public void OnGUI()
		{ 
			if (isFading)
			{			
				alpha += -1 * Settings.SCREEN_FADE_IN_SPEED * Time.deltaTime;  
    			alpha = Mathf.Clamp01(alpha);   

		    	GUI.color = new Color(255,255,255, alpha);		 
		    	GUI.depth = drawDepth;		 
				GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeTexture);			
			}
					
			if (alpha == 0)
				isFading = false;
		}
	}
}

